#include <QtCore/QCoreApplication>

#include <Ice/Ice.h> 
#include "ICE/Hello.h"
#include <string>

#ifdef _DEBUG
#pragma comment(lib, "Iced.lib")
#pragma comment(lib, "IceUtild.lib")
#else
#pragma comment(lib, "Ice.lib")
#pragma comment(lib, "IceUtil.lib")
#endif

using namespace std; 
using namespace Demo;

class PrinterI : public Printer { 
public: 
    virtual void printString(const string & s, 
        const Ice::Current &); 
    virtual string GetMsg(const Ice::Current &){ 
        cout << "Someone want a message..." << endl;
        return "This is return message."; 
    }

}; 

void PrinterI::printString(const string & s, const Ice::Current &) 
{ 
    static int i = 0;
    i++;
    cout << i <<" : " << s << endl; 
} 

int main(int argc, char* argv[]) 
{ 
    QCoreApplication a(argc, argv);

    int status = 0; 
    Ice::CommunicatorPtr ic; 
    try { 
        ic = Ice::initialize(argc, argv); 
        Ice::ObjectAdapterPtr adapter 
            = ic->createObjectAdapterWithEndpoints( 
            "SimplePrinterAdapter", "default -p 10000"); 
        Ice::ObjectPtr object = new PrinterI; 
        adapter->add(object, 
            ic->stringToIdentity("SimplePrinter")); 
        adapter->activate(); 
        ic->waitForShutdown(); 
    } catch (const Ice::Exception & e) { 
        cerr << e << endl; 
        status = 1; 
    } catch (const char * msg) { 
        cerr << msg << endl; 
        status = 1; 
    } 
    if (ic) 
    {
        ic->destroy(); 
    }

    return a.exec();
} 
